package com.cjl.dental_clinic.controller;

import com.cjl.dental_clinic.Req.AppointmentListReq;
import com.cjl.dental_clinic.Req.AppointmentReq;
import com.cjl.dental_clinic.base.BaseController;
import com.cjl.dental_clinic.base.ResVo;
import com.cjl.dental_clinic.entity.Appointment;
import com.cjl.dental_clinic.service.AppointmentService;
import com.cjl.dental_clinic.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: cjl
 * @time: 2024/04/09 14:27
 */
@RestController
@RequestMapping("cjl/appointment")
public class AppointmentController extends BaseController<Appointment, AppointmentService> {
    @Autowired
    private PatientService patientService;
    public AppointmentController(AppointmentService baseService) {
        super(baseService);
    }

    /**
     * 预约
     */
    @PostMapping("add")
    public ResVo<Boolean> add(AppointmentReq appointmentReq){
        return ResVo.ok(baseService.addAppointment(appointmentReq));
    }

    /**
     * 预约列表
     */
    @PostMapping("list")
    public ResVo<List<AppointmentListReq>> list(AppointmentListReq req){
        return ResVo.ok(baseService.listAppointment(req));
    }

    /**
     * 取消预约
     */
    @PostMapping("del")
    public ResVo<Boolean> del(Integer id){
        Appointment byId = baseService.getById(id);
        patientService.updateStatus(byId.getPatientId(),1);
        return ResVo.ok(baseService.removeById(id));
    }
}
